
package com.example.hcd.adapt;

import java.util.ArrayList;

import com.example.hcd.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * 快速创建list
 */
public class ViewUtils extends BaseAdapter {
    private ArrayList<String> mList = new ArrayList<String>();
    private LayoutInflater mInflate;
    private int Rid;

    // 用ImageSpan对象替换face

    public ViewUtils(Context context,int Rid) {
        mInflate = LayoutInflater.from(context);
        this.Rid =Rid;
    }

    public void setList(ArrayList<String> list) {
        if (mList != null) {
            mList.clear();
            mList.addAll(list);
        } else {
            mList = list;
        }
        notifyDataSetInvalidated();
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList == null ? null : mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflate.inflate(Rid, null);
        }

        String item = mList.get(position);
		TextView content = (TextView) convertView.findViewById(R.id.menu_text);
		content.setText(item);
		if(Rid == R.layout.work_menu_item)
		{
			switch (position) {
			case 0:
				convertView.findViewById(R.id.image_icon).setBackgroundResource(R.drawable.menuitem02);
				break;
			
			case 1:
				convertView.findViewById(R.id.image_icon).setBackgroundResource( R.drawable.menuitem03);
				break;
			case 2:
				convertView.findViewById(R.id.image_icon).setBackgroundResource( R.drawable.menuitem07);
				break;

			default:
				break;
			}
			
		}
		
		
		
        return convertView;
    }
    
}
